package org.jeecg.modules.basesource.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.basesource.entity.*;
import org.jeecg.modules.basesource.service.*;
import org.jeecg.modules.basesource.utils.cwbb.CwbbQykjzzWrapperUtil;
import org.jeecg.modules.basesource.utils.cwbb.CwbbXqyWrapperUtil;
import org.jeecg.modules.basesource.utils.cwbb.CwbbYbqyWrapperUtil;
import org.jeecg.modules.basesource.utils.cwbb.CwbbYbqyyzxWrapperUtil;
import org.jeecg.modules.basesource.vo.QykjzdCwbbVo;
import org.jeecg.modules.basesource.vo.QykjzzYbqyCwbbVo;
import org.jeecg.modules.basesource.vo.QykjzzYbqyyzxCwbbVo;
import org.jeecg.modules.basesource.vo.XqykjzzCwbbVo;
import org.jeecg.modules.dzswj.vo.response.cwbb.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

/**
 * 财务报表服务类
 * @author chensherun on 2022/3/1.
 * @version 1.0
 */
@Slf4j
@Service
public class SbCwbbServiceImpl implements ISbCwbbService{

    @Autowired
    private ISbCwbbQykjzzLrbService qykjzzLrbService;
    @Autowired
    private ISbCwbbQykjzzXjllbService qykjzzXjllbService;
    @Autowired
    private ISbCwbbQykjzzybqyLrbService qykjzzybqyLrbService;
    @Autowired
    private ISbCwbbQykjzzybqyLrbyzxService qykjzzybqyLrbyzxService;
    @Autowired
    private ISbCwbbQykjzzybqyXjllbService qykjzzybqyXjllbService;
    @Autowired
    private ISbCwbbQykjzzybqyXjllbyzxService qykjzzybqyXjllbyzxService;
    @Autowired
    private ISbCwbbQykjzzybqyZcfzbService qykjzzybqyZcfzbService;
    @Autowired
    private ISbCwbbQykjzzybqyZcfzbyzxService qykjzzybqyZcfzbyzxService;
    @Autowired
    private ISbCwbbQykjzzZcfzbService qykjzzZcfzbService;
    @Autowired
    private ISbCwbbXqykjzzLrbNbService xqykjzzLrbNbService;
    @Autowired
    private ISbCwbbXqykjzzLrbService xqykjzzLrbService;
    @Autowired
    private ISbCwbbXqykjzzXjllbNbService xqykjzzXjllbNbService;
    @Autowired
    private ISbCwbbXqykjzzXjllbService xqykjzzXjllbService;
    @Autowired
    private ISbCwbbXqykjzzZcfzbService xqykjzzZcfzbService;
    @Autowired
    private ISbCwbbBwService cwbbBwService;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveJbCwbb(String tynsrsbh, String nsrmc, String ssqq, String ssqz, GsCwbbVo gsCwbbVo) {
        //判断使用哪种会计制度
        Date dateSsqq = null;
        Date dateSsqz = null;
        try {
            dateSsqq = DateUtils.parseDate(ssqq, "yyyy-MM-dd");
            dateSsqz = DateUtils.parseDate(ssqz, "yyyy-MM-dd");
        } catch (ParseException e) {
            throw new JeecgBootException("属期日期格式错误");
        }
        //适用于101，102，201三个才保存原始报文
        boolean isSaveBw = false;
        //一般企业
        if (gsCwbbVo.getYbqylrbVO() != null
                || gsCwbbVo.getYbqyxjllbVO() != null
                || gsCwbbVo.getYbqyzcfzbVO() != null
                || gsCwbbVo.getYbqylrbyzxVO() != null
                || gsCwbbVo.getYbqyzcfzbyzxVO() != null) {
            isSaveBw = true;

            //判断是否已执行新金融
            if (gsCwbbVo.getYbqylrbyzxVO() != null
                    || gsCwbbVo.getYbqyzcfzbyzxVO() != null) {
                QykjzzYbqyyzxCwbbVo wrapperCwbbVo = wrapperYbqyyzx(gsCwbbVo, tynsrsbh, nsrmc, dateSsqq, dateSsqz);
                //利润表,现金流量表,资产负债表
                SbCwbbQykjzzybqyLrbyzx lrb = wrapperCwbbVo.getLrb();
                SbCwbbQykjzzybqyXjllbyzx xjllb = wrapperCwbbVo.getXjllb();
                SbCwbbQykjzzybqyZcfzbyzx zcfzb = wrapperCwbbVo.getZcfzb();
                //保存到数据库
                if (lrb != null) {
                    qykjzzybqyLrbyzxService.saveOrUpdateByMultiId(lrb);
                }
                if (xjllb != null) {
                    qykjzzybqyXjllbyzxService.saveOrUpdateByMultiId(xjllb);
                }
                if (zcfzb != null) {
                    qykjzzybqyZcfzbyzxService.saveOrUpdateByMultiId(zcfzb);
                }
            } else {
                //解析包装实体对象
                QykjzzYbqyCwbbVo wrapperCwbbVo = wrapperYbqy(gsCwbbVo, tynsrsbh, nsrmc, dateSsqq, dateSsqz);
                //利润表,现金流量表,资产负债表
                SbCwbbQykjzzybqyLrb lrb = wrapperCwbbVo.getLrb();
                SbCwbbQykjzzybqyXjllb xjllb = wrapperCwbbVo.getXjllb();
                SbCwbbQykjzzybqyZcfzb zcfzb = wrapperCwbbVo.getZcfzb();
                //保存到数据库
                if (lrb != null) {
                    qykjzzybqyLrbService.saveOrUpdateByMultiId(lrb);
                }
                if (xjllb != null) {
                    qykjzzybqyXjllbService.saveOrUpdateByMultiId(xjllb);
                }
                if (zcfzb != null) {
                    qykjzzybqyZcfzbService.saveOrUpdateByMultiId(zcfzb);
                }
            }
        } else if (gsCwbbVo.getSyxqylrb() != null
                || gsCwbbVo.getSyxqyxjllb() != null
                || gsCwbbVo.getSyxqyzcfzb() != null) {
            isSaveBw = true;
            XqykjzzCwbbVo wrapperCwbbVo = wrapperXqy(gsCwbbVo, tynsrsbh, nsrmc, dateSsqq, dateSsqz);
            //小企业 102
            SbCwbbXqykjzzLrb lrb = wrapperCwbbVo.getLrb();
            SbCwbbXqykjzzXjllb xjllb = wrapperCwbbVo.getXjllb();
            SbCwbbXqykjzzZcfzb zcfzb = wrapperCwbbVo.getZcfzb();
            //保存到数据库
            if (lrb != null) {
                xqykjzzLrbService.saveOrUpdateByMultiId(lrb);
            }
            if (xjllb != null) {
                xqykjzzXjllbService.saveOrUpdateByMultiId(xjllb);
            }
            if (zcfzb != null) {
                xqykjzzZcfzbService.saveOrUpdateByMultiId(zcfzb);
            }
        } else if (gsCwbbVo.getQykjzdcwbbzcfzbVO() != null) {
            isSaveBw = true;
            //企业会计制度（2001） 201
            QykjzdCwbbVo wrapperCwbbVo = wrapperQykjzz(gsCwbbVo, tynsrsbh, nsrmc, dateSsqq, dateSsqz);
            SbCwbbQykjzzLrb lrb = wrapperCwbbVo.getLrb();
            SbCwbbQykjzzXjllb xjllb = wrapperCwbbVo.getXjllb();
            SbCwbbQykjzzZcfzb zcfzb = wrapperCwbbVo.getZcfzb();
            //保存到数据库
            if (lrb != null) {
                qykjzzLrbService.saveOrUpdateByMultiId(lrb);
            }
            if (xjllb != null) {
                qykjzzXjllbService.saveOrUpdateByMultiId(xjllb);
            }
            if (zcfzb != null) {
                qykjzzZcfzbService.saveOrUpdateByMultiId(zcfzb);
            }
        }

        //再将报文保存到展示财报表
        if (isSaveBw) {
            SbCwbbBw sbCwbbBw = new SbCwbbBw();
            sbCwbbBw.setTynsrsbh(tynsrsbh);
            sbCwbbBw.setNsrmc(nsrmc);
            sbCwbbBw.setSkssqq(ssqq);
            sbCwbbBw.setSkssqz(ssqz);
            sbCwbbBw.setJsonBw(JSON.toJSONString(gsCwbbVo));
            cwbbBwService.saveOrUpdateByMultiId(sbCwbbBw);
        }
    }

    /**
     * 包装企业会计准则（一般企业）未执行新金融..的利润表，现金流量表，资产负债表成实体对象
     * @param gsCwbbVo
     * @param tynsrsbh
     * @param nsrmc
     * @param dateSsqq
     * @param dateSsqz
     */
    private QykjzzYbqyCwbbVo wrapperYbqy(GsCwbbVo gsCwbbVo, String tynsrsbh, String nsrmc, Date dateSsqq, Date dateSsqz) {
        SbCwbbQykjzzybqyLrb lrb = null;
        SbCwbbQykjzzybqyXjllb xjllb = null;
        SbCwbbQykjzzybqyZcfzb zcfzb = null;
        //利润表实体封装
        if (gsCwbbVo.getYbqylrbVO() != null
                && gsCwbbVo.getYbqylrbVO().getYbqylrbGrid() != null
                && gsCwbbVo.getYbqylrbVO().getYbqylrbGrid().getYbqylrbGridlb() != null) {
            lrb = new SbCwbbQykjzzybqyLrb();
            BeanUtils.copyProperties(gsCwbbVo, lrb);
            lrb.setTynsrsbh(tynsrsbh);
            lrb.setNsrmc(nsrmc);
            lrb.setSkssqq(dateSsqq);
            lrb.setSkssqz(dateSsqz);
            lrb.setKjzdzzDm("101");
            lrb.setKjzdzzmc("企业会计制度");
            lrb.setZlbscjuuid("-");
            lrb.setZlbsdlDm("ZL1001");
            lrb.setZlbsdlmc("财务报表报送与信息采集");
            lrb.setZlbsxlDm("ZL1001001");
            lrb.setZlbsxlmc("财务报表报送与信息采集（企业会计准则一般企业）");
            List<YbqylrbGridlb> ybqylrbGridlb = gsCwbbVo.getYbqylrbVO().getYbqylrbGrid().getYbqylrbGridlb();
            NsrxxForm lrbNsrForm = gsCwbbVo.getYbqylrbVO().getNsrxxForm2();
            CwbbYbqyWrapperUtil.wrapperQykjzzybqyLrb(lrb, lrbNsrForm, ybqylrbGridlb);
        }

        //现金流量表实体封装
        if (gsCwbbVo.getYbqyxjllbVO() != null
                && gsCwbbVo.getYbqyxjllbVO().getYbqyxjllbGrid() != null
                && gsCwbbVo.getYbqyxjllbVO().getYbqyxjllbGrid().getYbqyxjllbGridlb() != null) {
            xjllb = new SbCwbbQykjzzybqyXjllb();
            BeanUtils.copyProperties(gsCwbbVo, xjllb);
            xjllb.setTynsrsbh(tynsrsbh);
            xjllb.setNsrmc(nsrmc);
            xjllb.setSkssqq(dateSsqq);
            xjllb.setSkssqz(dateSsqz);
            xjllb.setKjzdzzDm("101");
            xjllb.setKjzdzzmc("企业会计制度");
            xjllb.setZlbscjuuid("-");
            xjllb.setZlbsdlDm("ZL1001");
            xjllb.setZlbsdlmc("财务报表报送与信息采集");
            xjllb.setZlbsxlDm("ZL1001001");
            xjllb.setZlbsxlmc("财务报表报送与信息采集（企业会计准则一般企业）");
            List<YbqyxjllbGridlb> ybqyxjllbGridlb = gsCwbbVo.getYbqyxjllbVO().getYbqyxjllbGrid().getYbqyxjllbGridlb();
            NsrxxForm xjllbNsrForm = gsCwbbVo.getYbqyxjllbVO().getNsrxxForm3();
            CwbbYbqyWrapperUtil.wrapperQykjzzybqyXjllb(xjllb, xjllbNsrForm, ybqyxjllbGridlb);
        }

        //资产负债表实体封装
        if (gsCwbbVo.getYbqyzcfzbVO() != null
                && gsCwbbVo.getYbqyzcfzbVO().getYbqyzcfzbzbGrid() != null
                && gsCwbbVo.getYbqyzcfzbVO().getYbqyzcfzbzbGrid().getYbqyzcfzbzbGridlb() != null) {
            zcfzb = new SbCwbbQykjzzybqyZcfzb();
            BeanUtils.copyProperties(gsCwbbVo, zcfzb);
            zcfzb.setTynsrsbh(tynsrsbh);
            zcfzb.setNsrmc(nsrmc);
            zcfzb.setSkssqq(dateSsqq);
            zcfzb.setSkssqz(dateSsqz);
            zcfzb.setKjzdzzDm("101");
            zcfzb.setKjzdzzmc("企业会计制度");
            zcfzb.setZlbscjuuid("-");
            zcfzb.setZlbsdlDm("ZL1001");
            zcfzb.setZlbsdlmc("财务报表报送与信息采集");
            zcfzb.setZlbsxlDm("ZL1001001");
            zcfzb.setZlbsxlmc("财务报表报送与信息采集（企业会计准则一般企业）");
            List<YbqyzcfzbzbGridlb> ybqyzcfzbzbGridlb = gsCwbbVo.getYbqyzcfzbVO().getYbqyzcfzbzbGrid().getYbqyzcfzbzbGridlb();
            NsrxxForm zcfzbNsrForm = gsCwbbVo.getYbqyzcfzbVO().getNsrxxForm1();
            CwbbYbqyWrapperUtil.wrapperQykjzzybqyZcfzb(zcfzb, zcfzbNsrForm, ybqyzcfzbzbGridlb);
        }
        return new QykjzzYbqyCwbbVo().setLrb(lrb).setXjllb(xjllb).setZcfzb(zcfzb);
    }

    /**
     * 包装企业会计准则（一般企业）已执行新金融..的利润表，现金流量表，资产负债表成实体对象
     * @param gsCwbbVo
     * @param tynsrsbh
     * @param nsrmc
     * @param dateSsqq
     * @param dateSsqz
     */
    private QykjzzYbqyyzxCwbbVo wrapperYbqyyzx(GsCwbbVo gsCwbbVo, String tynsrsbh, String nsrmc, Date dateSsqq, Date dateSsqz){
        SbCwbbQykjzzybqyLrbyzx lrb = null;
        SbCwbbQykjzzybqyXjllbyzx xjllb = null;
        SbCwbbQykjzzybqyZcfzbyzx zcfzb = null;
        //利润表实体封装
        if (gsCwbbVo.getYbqylrbyzxVO() != null
                && gsCwbbVo.getYbqylrbyzxVO().getYbqylrbyzxGrid() != null
                && gsCwbbVo.getYbqylrbyzxVO().getYbqylrbyzxGrid().getYbqylrbyzxGridlb() != null) {
            lrb = new SbCwbbQykjzzybqyLrbyzx();
            BeanUtils.copyProperties(gsCwbbVo, lrb);
            lrb.setTynsrsbh(tynsrsbh);
            lrb.setNsrmc(nsrmc);
            lrb.setSkssqq(dateSsqq);
            lrb.setSkssqz(dateSsqz);
            lrb.setKjzdzzDm("101");
            lrb.setKjzdzzmc("企业会计制度");
            lrb.setZlbscjuuid("-");
            lrb.setZlbsdlDm("ZL1001");
            lrb.setZlbsdlmc("财务报表报送与信息采集");
            lrb.setZlbsxlDm("ZL1001001");
            lrb.setZlbsxlmc("财务报表报送与信息采集（企业会计准则一般企业）");
            List<YbqylrbyzxGridlb> lrbGridlb = gsCwbbVo.getYbqylrbyzxVO().getYbqylrbyzxGrid().getYbqylrbyzxGridlb();
            NsrxxForm lrbNsrForm = gsCwbbVo.getYbqylrbyzxVO().getNsrxxForm2();
            CwbbYbqyyzxWrapperUtil.wrapperQykjzzybqyyzxLrb(lrb, lrbNsrForm, lrbGridlb);
        }

        //现金流量表实体封装
        if (gsCwbbVo.getYbqyxjllbVO() != null
                && gsCwbbVo.getYbqyxjllbVO().getYbqyxjllbGrid() != null
                && gsCwbbVo.getYbqyxjllbVO().getYbqyxjllbGrid().getYbqyxjllbGridlb() != null) {
            xjllb = new SbCwbbQykjzzybqyXjllbyzx();
            BeanUtils.copyProperties(gsCwbbVo, xjllb);
            xjllb.setTynsrsbh(tynsrsbh);
            xjllb.setNsrmc(nsrmc);
            xjllb.setSkssqq(dateSsqq);
            xjllb.setSkssqz(dateSsqz);
            xjllb.setKjzdzzDm("101");
            xjllb.setKjzdzzmc("企业会计制度");
            xjllb.setZlbscjuuid("-");
            xjllb.setZlbsdlDm("ZL1001");
            xjllb.setZlbsdlmc("财务报表报送与信息采集");
            xjllb.setZlbsxlDm("ZL1001001");
            xjllb.setZlbsxlmc("财务报表报送与信息采集（企业会计准则一般企业）");
            List<YbqyxjllbGridlb> xjllbGridlb = gsCwbbVo.getYbqyxjllbVO().getYbqyxjllbGrid().getYbqyxjllbGridlb();
            NsrxxForm xjllbNsrForm = gsCwbbVo.getYbqyxjllbVO().getNsrxxForm3();
            CwbbYbqyyzxWrapperUtil.wrapperQykjzzybqyyzxXjllb(xjllb, xjllbNsrForm, xjllbGridlb);
        }

        //资产负债表实体封装
        if (gsCwbbVo.getYbqyzcfzbyzxVO() != null
                && gsCwbbVo.getYbqyzcfzbyzxVO().getYbqyzcfzbzbyzxGrid() != null
                && gsCwbbVo.getYbqyzcfzbyzxVO().getYbqyzcfzbzbyzxGrid().getYbqyzcfzbzbyzxGridlb() != null) {
            zcfzb = new SbCwbbQykjzzybqyZcfzbyzx();
            BeanUtils.copyProperties(gsCwbbVo, zcfzb);
            zcfzb.setTynsrsbh(tynsrsbh);
            zcfzb.setNsrmc(nsrmc);
            zcfzb.setSkssqq(dateSsqq);
            zcfzb.setSkssqz(dateSsqz);
            zcfzb.setKjzdzzDm("101");
            zcfzb.setKjzdzzmc("企业会计制度");
            zcfzb.setZlbscjuuid("-");
            zcfzb.setZlbsdlDm("ZL1001");
            zcfzb.setZlbsdlmc("财务报表报送与信息采集");
            zcfzb.setZlbsxlDm("ZL1001001");
            zcfzb.setZlbsxlmc("财务报表报送与信息采集（企业会计准则一般企业）");
            List<YbqyzcfzbzbyzxGridlb> zbzbGridlb = gsCwbbVo.getYbqyzcfzbyzxVO().getYbqyzcfzbzbyzxGrid().getYbqyzcfzbzbyzxGridlb();
            NsrxxForm zcfzbNsrForm = gsCwbbVo.getYbqyzcfzbyzxVO().getNsrxxForm1();
            CwbbYbqyyzxWrapperUtil.wrapperQykjzzybqyyzxZcfzb(zcfzb, zcfzbNsrForm, zbzbGridlb);
        }
        return new QykjzzYbqyyzxCwbbVo().setLrb(lrb).setXjllb(xjllb).setZcfzb(zcfzb);
    }

    /**
     * 包装小企业会计准则的利润表，现金流量表，资产负债表成实体对象
     * @param gsCwbbVo
     * @param tynsrsbh
     * @param nsrmc
     * @param dateSsqq
     * @param dateSsqz
     */
    private XqykjzzCwbbVo wrapperXqy(GsCwbbVo gsCwbbVo, String tynsrsbh, String nsrmc, Date dateSsqq, Date dateSsqz){
        SbCwbbXqykjzzLrb lrb = null;
        SbCwbbXqykjzzXjllb xjllb = null;
        SbCwbbXqykjzzZcfzb zcfzb = null;
        //gsCwbbVo.getXqylrbnb()年报
        if (gsCwbbVo.getSyxqylrb() != null
                && gsCwbbVo.getSyxqylrb().getSyxqylrbGrid() != null
                && gsCwbbVo.getSyxqylrb().getSyxqylrbGrid().getSyxqylrbGridlb() != null) {
            lrb = new SbCwbbXqykjzzLrb();
            BeanUtils.copyProperties(gsCwbbVo, lrb);
            lrb.setTynsrsbh(tynsrsbh);
            lrb.setNsrmc(nsrmc);
            lrb.setSkssqq(dateSsqq);
            lrb.setSkssqz(dateSsqz);
            lrb.setKjzdzzDm("102");
            lrb.setKjzdzzmc("小企业会计准则");
            lrb.setZlbscjuuid("-");
            lrb.setZlbsdlDm("ZL1001");
            lrb.setZlbsdlmc("财务报表报送与信息采集");
            lrb.setZlbsxlDm("ZL1001003");
            lrb.setZlbsxlmc("财务报表报送与信息采集（小企业会计准则）");
            List<XqylrbnbGridlb> syxqylrbGridlb = gsCwbbVo.getSyxqylrb().getSyxqylrbGrid().getSyxqylrbGridlb();
            NsrxxForm nsrxxForm = gsCwbbVo.getSyxqylrb().getNsrxxForm2();
            CwbbXqyWrapperUtil.wrapperXqykjzzLrb(lrb, nsrxxForm, syxqylrbGridlb);
        }
        if (gsCwbbVo.getSyxqyxjllb() != null
                && gsCwbbVo.getSyxqyxjllb().getXqyxjllbGrid() != null
                && gsCwbbVo.getSyxqyxjllb().getXqyxjllbGrid().getXqyxjllbGridlb() != null) {
            xjllb = new SbCwbbXqykjzzXjllb();
            BeanUtils.copyProperties(gsCwbbVo, xjllb);
            xjllb.setTynsrsbh(tynsrsbh);
            xjllb.setNsrmc(nsrmc);
            xjllb.setSkssqq(dateSsqq);
            xjllb.setSkssqz(dateSsqz);
            xjllb.setKjzdzzDm("102");
            xjllb.setKjzdzzmc("小企业会计准则");
            xjllb.setZlbscjuuid("-");
            xjllb.setZlbsdlDm("ZL1001");
            xjllb.setZlbsdlmc("财务报表报送与信息采集");
            xjllb.setZlbsxlDm("ZL1001003");
            xjllb.setZlbsxlmc("财务报表报送与信息采集（小企业会计准则）");
            List<XqyxjllbnGridlb> xqyxjllbGridlb = gsCwbbVo.getSyxqyxjllb().getXqyxjllbGrid().getXqyxjllbGridlb();
            NsrxxForm nsrxxForm = gsCwbbVo.getSyxqyxjllb().getNsrxxForm3();
            CwbbXqyWrapperUtil.wrapperXqykjzzXjllb(xjllb, nsrxxForm, xqyxjllbGridlb);
        }
        if (gsCwbbVo.getSyxqyzcfzb() != null
                && gsCwbbVo.getSyxqyzcfzb().getSyxqyzcfzbGrid() != null
                && gsCwbbVo.getSyxqyzcfzb().getSyxqyzcfzbGrid().getXqyzcfzbGridlb() != null) {
            zcfzb = new SbCwbbXqykjzzZcfzb();
            BeanUtils.copyProperties(gsCwbbVo, zcfzb);
            zcfzb.setTynsrsbh(tynsrsbh);
            zcfzb.setNsrmc(nsrmc);
            zcfzb.setSkssqq(dateSsqq);
            zcfzb.setSkssqz(dateSsqz);
            zcfzb.setKjzdzzDm("102");
            zcfzb.setKjzdzzmc("小企业会计准则");
            zcfzb.setZlbscjuuid("-");
            zcfzb.setZlbsdlDm("ZL1001");
            zcfzb.setZlbsdlmc("财务报表报送与信息采集");
            zcfzb.setZlbsxlDm("ZL1001003");
            zcfzb.setZlbsxlmc("财务报表报送与信息采集（小企业会计准则）");
            List<XqyzcfzbGridlb> xqyzcfzbGridlb = gsCwbbVo.getSyxqyzcfzb().getSyxqyzcfzbGrid().getXqyzcfzbGridlb();
            NsrxxForm nsrxxForm = gsCwbbVo.getSyxqyzcfzb().getNsrxxForm1();
            CwbbXqyWrapperUtil.wrapperXqykjzzZcfzb(zcfzb, nsrxxForm, xqyzcfzbGridlb);
        }
        return new XqykjzzCwbbVo().setLrb(lrb).setXjllb(xjllb).setZcfzb(zcfzb);
    }

    /**
     * 包装企业会计制度的利润表，现金流量表，资产负债表成实体对象
     * @param gsCwbbVo
     * @param tynsrsbh
     * @param nsrmc
     * @param dateSsqq
     * @param dateSsqz
     */
    public QykjzdCwbbVo wrapperQykjzz(GsCwbbVo gsCwbbVo, String tynsrsbh, String nsrmc, Date dateSsqq, Date dateSsqz){
        SbCwbbQykjzzLrb lrb = null;
        SbCwbbQykjzzXjllb xjllb = null;
        SbCwbbQykjzzZcfzb zcfzb = null;
        if (gsCwbbVo.getQykjzdcwbblrbVO() != null
                && gsCwbbVo.getQykjzdcwbblrbVO().getQykjzdcwbblrbxxGrid() != null
                && gsCwbbVo.getQykjzdcwbblrbVO().getQykjzdcwbblrbxxGrid().getQykjzdcwbblrbxxGridlb() != null) {
            lrb = new SbCwbbQykjzzLrb();
            BeanUtils.copyProperties(gsCwbbVo, lrb);
            lrb.setTynsrsbh(tynsrsbh);
            lrb.setNsrmc(nsrmc);
            lrb.setSkssqq(dateSsqq);
            lrb.setSkssqz(dateSsqz);
            lrb.setKjzdzzDm("201");
            lrb.setKjzdzzmc("企业会计制度（2001）");
            lrb.setZlbscjuuid("-");
            lrb.setZlbsdlDm("ZL1001");
            lrb.setZlbsdlmc("财务报表报送与信息采集");
            lrb.setZlbsxlDm("ZL1001002");
            lrb.setZlbsxlmc("财务报表报送与信息采集（企业会计制度）");
            List<QykjzdcwbblrbxxGridlb> qykjzdcwbblrbxxGridlb = gsCwbbVo.getQykjzdcwbblrbVO().getQykjzdcwbblrbxxGrid().getQykjzdcwbblrbxxGridlb();
            NsrxxForm nsrxxForm = gsCwbbVo.getQykjzdcwbblrbVO().getNsrxxForm();
            CwbbQykjzzWrapperUtil.wrapperQykjzzLrb(lrb, nsrxxForm, qykjzdcwbblrbxxGridlb);
        }
        if (gsCwbbVo.getQykjzdcwbbxjllbVO() != null
                && gsCwbbVo.getQykjzdcwbbxjllbVO().getQykjzdcwbbxjllbxxGrid() != null
                && gsCwbbVo.getQykjzdcwbbxjllbVO().getQykjzdcwbbxjllbxxGrid().getQykjzdcwbbxjllbxxGridlb() != null) {
            xjllb = new SbCwbbQykjzzXjllb();
            BeanUtils.copyProperties(gsCwbbVo, xjllb);
            xjllb.setTynsrsbh(tynsrsbh);
            xjllb.setNsrmc(nsrmc);
            xjllb.setSkssqq(dateSsqq);
            xjllb.setSkssqz(dateSsqz);
            xjllb.setKjzdzzDm("201");
            xjllb.setKjzdzzmc("企业会计制度（2001）");
            xjllb.setZlbscjuuid("-");
            xjllb.setZlbsdlDm("ZL1001");
            xjllb.setZlbsdlmc("财务报表报送与信息采集");
            xjllb.setZlbsxlDm("ZL1001002");
            xjllb.setZlbsxlmc("财务报表报送与信息采集（企业会计制度）");
            List<QykjzdcwbbxjllbxxGridlb> qykjzdcwbbxjllbxxGridlb = gsCwbbVo.getQykjzdcwbbxjllbVO().getQykjzdcwbbxjllbxxGrid().getQykjzdcwbbxjllbxxGridlb();
            NsrxxForm nsrxxForm = gsCwbbVo.getQykjzdcwbbxjllbVO().getNsrxxForm();
            CwbbQykjzzWrapperUtil.wrapperQykjzzXjllb(xjllb, nsrxxForm, qykjzdcwbbxjllbxxGridlb);
        }
        if (gsCwbbVo.getQykjzdcwbbzcfzbVO() != null
                && gsCwbbVo.getQykjzdcwbbzcfzbVO().getBdxxGrid() != null
                && gsCwbbVo.getQykjzdcwbbzcfzbVO().getBdxxGrid().getZcfzbdxxGridlb() != null) {
            zcfzb = new SbCwbbQykjzzZcfzb();
            BeanUtils.copyProperties(gsCwbbVo, zcfzb);
            zcfzb.setTynsrsbh(tynsrsbh);
            zcfzb.setNsrmc(nsrmc);
            zcfzb.setSkssqq(dateSsqq);
            zcfzb.setSkssqz(dateSsqz);
            zcfzb.setKjzdzzDm("201");
            zcfzb.setKjzdzzmc("企业会计制度（2001）");
            zcfzb.setZlbscjuuid("-");
            zcfzb.setZlbsdlDm("ZL1001");
            zcfzb.setZlbsdlmc("财务报表报送与信息采集");
            zcfzb.setZlbsxlDm("ZL1001002");
            zcfzb.setZlbsxlmc("财务报表报送与信息采集（企业会计制度）");
            List<ZcfzbdxxGridlb> zcfzbdxxGridlb = gsCwbbVo.getQykjzdcwbbzcfzbVO().getBdxxGrid().getZcfzbdxxGridlb();
            NsrxxForm nsrxxForm = gsCwbbVo.getQykjzdcwbbzcfzbVO().getNsrxxForm();
            CwbbQykjzzWrapperUtil.wrapperQykjzzZcfzb(zcfzb, nsrxxForm, zcfzbdxxGridlb);
        }

        return new QykjzdCwbbVo().setLrb(lrb).setXjllb(xjllb).setZcfzb(zcfzb);
    }
}
